package com.asset.dispoal.dicData.service.commom;

import com.asset.dispoal.dicData.domain.db.entity.GbDictData;
import com.asset.dispoal.dicData.domain.db.mapper.GbDictDataMapper;
import com.asset.dispoal.dicData.dto.GbDictDataRequest;
import com.asset.dispoal.dicData.service.converter.GbDictDataConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.date.DateTimeUtil;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.id.BaseIdeable;
import tech.mhuang.pacebox.springboot.protocol.Result;

/**
 * @author qr
 * @date 2022/2/24$
 */
@Component
public class InsertDictDataCommand implements BaseCommand<GbDictDataRequest, Result> {

    @Autowired
    GbDictDataMapper gbDictDataMapper;

    @Autowired
    BaseIdeable<String> snowFlake;

    @Override
    public Result execute(GbDictDataRequest gbDictDataRequest) {

        final GbDictData gbDictData = GbDictDataConverter.INSTANCE.reqToDo(gbDictDataRequest);
        gbDictData.setDelFlag("0");
        gbDictData.setCreateTime(DateTimeUtil.currentDate());
        gbDictData.setId(snowFlake.generateId());
        gbDictDataMapper.insert(gbDictData);
        return Result.ok();
    }
}
